package com.thz.friend.controller.user;

import com.thz.common.core.constants.HttpConstants;
import com.thz.common.core.controller.BaseController;
import com.thz.common.core.pojo.vo.LoginUserVO;
import com.thz.common.core.result.Result;
import com.thz.friend.pojo.user.dto.UserDTO;
import com.thz.friend.pojo.user.dto.UserEmailDTO;
import com.thz.friend.pojo.user.dto.UserUpdateDTO;
import com.thz.friend.pojo.user.vo.UserVO;
import com.thz.friend.service.user.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description
 * @Author thz
 * @Date 2025/3/26
 */
@RestController
@RequestMapping("/user")
public class UserController extends BaseController {

    @Autowired
    private IUserService userService;

    @PostMapping("/sendCode")
    public Result sendCode(@RequestBody UserEmailDTO userEmailDTO) {
        return ToResult(userService.sendCode(userEmailDTO)) ;
    }

    @PostMapping("/code/login")
    public Result<String> codeLogin(@RequestBody UserDTO userDTO) {
        return Result.ok(userService.codeLogin(userDTO.getEmail(), userDTO.getCode()));
    }

    @DeleteMapping("/logout")
    public Result logout(@RequestHeader(HttpConstants.AUTHENTICATION) String token) {
        return ToResult(userService.logout(token));
    }

    @GetMapping("/info")
    public Result<LoginUserVO> info(@RequestHeader(HttpConstants.AUTHENTICATION) String token) {
        return Result.ok(userService.info(token));
    }

    @GetMapping("/detail")
    public Result<UserVO> detail() {
        return Result.ok(userService.detail());
    }

    @PutMapping("/edit")
    public Result edit(@RequestBody UserUpdateDTO userUpdateDTO) {
        return UToResult(userService.edit(userUpdateDTO));
    }

    @PutMapping("/head-image/update")
    public Result updateHeadImage(@RequestBody UserUpdateDTO userUpdateDTO) {
        return UToResult(userService.updateHeadImage(userUpdateDTO.getHeadImage()));
    }
}
